﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Web.UI.HtmlControls;

namespace WebSys.UI.Control.ZhengShou
{
    public class GetCompanyList1Control : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            if (!base.Page.IsPostBack)
            {
                Bind();
            }
            Button btn_query = (Button)FindControl("btn_query");
            btn_query.Click += new EventHandler(btn_query_Click);
            CustomGridView List = (CustomGridView)FindControl("List");
            List.OnLoadData += new EventHandler(List_OnLoadData);
        }

        protected void Bind()
        {
            TextBox txt_name = (TextBox)FindControl("txt_name");
            CustomGridView List = (CustomGridView)FindControl("List");
            List.RowCreated += new GridViewRowEventHandler(List_RowCreated);

            string dwname = txt_name.Text.Trim();
            string dwtype = HttpContext.Current.Request.QueryString["userType"].ToString();
            List<EluZSProvider.Company> company = _EluZSDataProvider.GetCompanyList(dwname, dwtype);
            List.DataSource = company;
            List.RecordCount = company.Count;
            List.HideColName = "ID";
            List.DataKeyNames = new string[] { "ID" };
            List.DataBind();
        }
        protected void List_RowCreated(object sender, GridViewRowEventArgs e)
        {
            TableCell cell = new TableCell();
            if (e.Row.RowType == DataControlRowType.Header)
            {
                TableHeaderCell cell1 = new TableHeaderCell();
                cell1.Text = "选择";
                e.Row.Cells.AddAt(0, cell1);
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                EluZSProvider.Company rows = (EluZSProvider.Company)e.Row.DataItem;
                HtmlInputCheckBox rb = new HtmlInputCheckBox();
                if (rows != null)
                {
                    e.Row.Attributes.Add("id", rows.Id);
                    rb.Attributes.Add("onclick", "setValue(this);");
                    rb.Attributes.Add("id", rows.Id + "|" + rows.单位名称);
                }
                else
                {
                    e.Row.Attributes.Add("id", "");
                    rb.ID = "";
                    rb.Attributes.Add("onclick", "setValue(this);");
                }
                cell.Controls.Add(rb);
                e.Row.Cells.AddAt(0, cell);
            }
        }

        protected void List_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected void btn_query_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}


